import dayjs from 'dayjs';
import 'dayjs/locale/zh-cn';
import relativeTime from 'dayjs/plugin/relativeTime';

dayjs.extend(relativeTime); //相对时间
dayjs.locale('zh-cn'); //使用本地化语言

const getHumanDateTime = (dateTime) => {
  if (!dateTime || dateTime === '') {
    return '-';
  }
  return dayjs(new Date(dateTime)).fromNow().replace(' ', '');
};

const DayjsUtil = {
  dayjs,
  getHumanDateTime
};

export default DayjsUtil;
